import {createRouter,createWebHashHistory} from "vue-router"
const Home = ()=> import('../views/Home.vue');
const About = ()=> import('../views/About.vue');
const Product = ()=>import('../views/Product.vue');
//引入用户中心
const UserCenter = ()=> import("../views/user-center/index.vue");
//引入用户中心的信息页
const UserProfile = ()=> import("../views/user-center/Profile.vue");
//引入用户中心的个人设置页
const UserSettings = ()=> import("../views/user-center/Settings.vue");
//引入404页
const NotFound = () =>import("../views/404.vue");
//引入Vuex页
const VuexPage = () =>import("../views/vuex.vue")


const routes = [
    {
        path: '/',
        name: 'home',
        component: Home
    },
    {
        path: '/about',
        name: 'about',
        component: About
    },
    {
        path: '/vuex',
        name: 'vuexPage',
        component:VuexPage
    },
    {
        path:'/product/:id',
        name:'product',
        component:Product
    },
    {
        path: "/user",
        name: "userCenter",
        component: UserCenter,
        redirect: '/user/profile',
        children: [
            {
                path: 'profile',
                name: 'profile',
                component: UserProfile,
            },
            {
                path: 'Settings',
                name: 'Settings',
                component: UserSettings,
            },
        ]

    },
    {
        path: "/:pathMatch(.*)*",
        name: 'notFound',
        component: NotFound
    }
]
console.log('routes', routes);

const router = createRouter({
    history: createWebHashHistory(),
    routes
})

// router.beforeEach((to, from, next)=>{
//     console.log('to',to);
//     console.log('from',from);
    // if(to.name == 'userCenter'){
    //     if(isFinitelogin){
    //         next()
    //     }else{
    //         next({name:'login'})
    //     }
    // }else{

    // next()
    // }
    
// })

// router.afterEach((to.from) =>{
//     console.log('后备守卫to',to);
//     console.log('后备守卫from',from);
// })
export default router